﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PluggableModulesInterface;
using StorageManagement;
using SMSROUTER.Business;
using System.Threading.Tasks;
using PluggableModulesRouter;
using Settings;

namespace StaticThreadManagement
{
    public class MTUpdateReportFRRTheadManage : WorkingBase
    {
        protected override int INFINITE_NEXT_TIME
        {
            get { return AppSetting.UpdateDataDuration; }
        }

        protected override void LoopWorking()
        {
            try
            {
                List<SmsRouter> listRouter = SmsRouter.GetInstance();
                Task[] task = new Task[listRouter.Count];
                int i = 0;
                foreach (SmsRouter router in SmsRouter.GetInstance())
                {
                    task[i++] = Task.Factory.StartNew(tkey =>
                    {
                        SmsRouterReport.UpdateToOutReport((int)tkey, Settings.AppSetting.Status.SENTGATEWAY);
                    }, router.RouterID);
                }
                Task.WaitAll(task);
            }
            catch (AggregateException ae)
            {
                foreach (var e in ae.InnerExceptions)
                    HandleException(e, AppSetting.WarningType.mt_error);
            }
            catch (Exception ex)
            {
                HandleException(ex, AppSetting.WarningType.mt_error);
            }
        }
    }
}
